package com.yikaiye.android.yikaiye.config;

import com.yikaiye.android.yikaiye.model.UserModel;
import com.yikaiye.android.yikaiye.utils.sharedpreference.SPUtil;

/**
 * 用户信息管理
 */
public class UserManager {
    private static UserManager INSTANCE = null;
    private String IS_LOGIN = "is_login";
    private String TOKEN = "token";
    private String PHONE = "phone";
    private String USER_ID = "userId";
    private String AVATAR = "avatar";
    private String USER_NAME = "username";
    private String USER_DETAIL_ID = "userDetailId";
    private String COMPANY_NAME = "companyName";
    private String REAL_NAME = "realName";

    public static UserManager getInstance() {
        if (INSTANCE == null) {
            INSTANCE = new UserManager();
        }
        return INSTANCE;
    }

    public void saveUserInfo(UserModel userModel) {
        setLogin(true);
        setToken("TOKEN " + userModel.getAccessToken());
        setAvatar(userModel.getAvatar());
        setPhone(userModel.getPhone());
        setUserId(userModel.getUserId());
        setUsername(userModel.getUsername());
        setUserDetailId(userModel.getUserDetailId());
        setCompanyName(userModel.getCompanyName());
    }

    public void clearUserInfo() {
        setLogin(false);
        setToken("");
        setAvatar("");
        setPhone("");
        setUserId("");
        setUsername("");
        setUserDetailId("");
        setCompanyName("");
    }

    public boolean isLogin() {
        return SPUtil.getBoolean(IS_LOGIN, false);
    }

    public void setLogin(boolean isLogin) {
        SPUtil.put(IS_LOGIN, isLogin);
    }

    public void setToken(String token) {
        SPUtil.put(TOKEN, token);
    }

    public String getToken() {
        return SPUtil.getString(TOKEN, "");
    }

    public String getPhone() {
        return SPUtil.getString(PHONE, "");
    }

    public void setPhone(String phone) {
        SPUtil.put(PHONE, phone);
    }

    public String getUserId() {
        return SPUtil.getString(USER_ID, "");
    }

    public void setUserId(String userId) {
        SPUtil.put(USER_ID, userId);
    }

    public String getAvatar() {
        return SPUtil.getString(AVATAR, "");
    }

    public void setAvatar(String avatar) {
        SPUtil.put(AVATAR, avatar);
    }

    public String getUsername() {
        return SPUtil.getString(USER_NAME, "");
    }

    public void setUsername(String username) {
        SPUtil.put(USER_NAME, username);
    }

    public void setUserDetailId(String uid) {
        SPUtil.put(USER_DETAIL_ID, uid);
    }

    public String getUserDetailId() {
        return SPUtil.getString(USER_DETAIL_ID, "");
    }

    public void setCompanyName(String companyName) {
        SPUtil.put(COMPANY_NAME, companyName);
    }

    public String getCompanyName() {
        return SPUtil.getString(COMPANY_NAME, "");
    }

    public void setRealName(String realName) {
        SPUtil.put(REAL_NAME, realName);
    }

    public String getRealName() {
        return SPUtil.getString(REAL_NAME, "");
    }
}

